$(function (){
    template.defaults.imports.formatDate = function (date) {
        date=new Date(data)
        var year = date.getFullYear()
        var month = date.getMonth() + 1
        var day = date.getDate()
        return year+'-'+month+'-'+day
    }

//获取数据库信息渲染到页面
    function Xuan(){
        $.ajax({
            type:'get',
            url:'admin/comments',
            success:function(res){
                console.log(res);
                var tags=template('table-tpl',res)
                $('.layui-table tbody').html(tags)
            }
        })
    }


    Xuan();
    //删除
    $('.layui-table tbody').on('click','button',function(e){
    //  console.log(123);
    // var id =$(this).data(id)
    var id = $(e.target).data('id')
    layer.confirm('是否确认删除？',function(index){
      $.ajax({
          type:'DELETE',
          url:'admin/comments/'+id,
          success:function(res){
              if(res.status===0){
                  layer.close(index)
                  Xuan();
              }
          }
      })
    })
    })
})

